<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <dl>
        <dt>
            <input type="checkbox" name="" class="checkAll" id="checkAll">
        </dt>
        <dd>
            <input class="checkItem" type="checkbox" name="" id="">
        </dd>
        <dd> <input class="checkItem" type="checkbox" name="" id=""></dd>
        <dd> <input class="checkItem" type="checkbox" name="" id=""></dd>
        <dd> <input class="checkItem" type="checkbox" name="" id=""></dd>
        <dd> <input class="checkItem" type="checkbox" name="" id=""></dd>
    </dl>
</body>
<script>
    let checkAll = document.getElementById("checkAll");
    let checkItems = document.getElementsByClassName("checkItem");
    checkAll.onclick = function () {
        debugger
        let ischeck = checkAll.checked;

        for (let i = 0; i < checkItems.length; i++) {
            checkItems[i].checked = ischeck;

        }

    };
   
    for (let i = 0; i < checkItems.length; i++) {
        const element = checkItems[i];
        element.onclick=function(){
            let isCheckAll = true;
            for (let i = 0; i < checkItems.length; i++) {
                if(!checkItems[i].checked){
                    isCheckAll = false; //有非选中项目
                } 

            }
            checkAll.checked = isCheckAll;
        }
        
    }
  
    
</script>

</html>